﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Zen4SyncDashboard.DAL
{
    public partial class syncSessionContext : IDataErrorInfo
    {
        #region - IDataErrorInfo Members -

        public string Error { get { return null; } }

        public string this[string columnName]
        {
            get { return GetValidationError(columnName); }
        }

        #endregion - IDataErrorInfo Members -

        #region - Validation -

        static readonly string[] ValidatedProperties = 
        {
            "syncSessionContext_name"
        };

        public bool IsValid()
        {
            foreach (string property in ValidatedProperties)
                if (GetValidationError(property) != null)
                    return false;

            return true;
        }

        string GetValidationError(string propertyName)
        {
            if (!ValidatedProperties.Contains(propertyName))
                return null;

            string error = null;

            switch (propertyName)
            {
                case "syncSessionContext_name":
                    error = ValidateName();
                    break;

                default:
                    throw new ArgumentException("Unrecognized property: " + propertyName);
            }

            return error;
        }

        private string ValidateName()
        {
            if (string.IsNullOrWhiteSpace(syncSessionContext_name))
                return "Name can't be empty";

            return null;    
        }

        #endregion - Validation -
    }
}
